package cn.edu.gdut.deepcode.domain.po;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import static cn.edu.gdut.deepcode.constant.ReqRespConstant.*;

/**
 * <p>
 * 统一响应实体
 * </p>
 *
 * @Author: 暮倦
 * @Since: 2025-04-08  21:04
 * @Version: 1.0.0
 */
@Data
@Accessors(chain = true)
@ApiModel("统一响应实体,泛型表示data属性的数据类型")
@NoArgsConstructor
@AllArgsConstructor
public class Result<T>{
    @ApiModelProperty(value = "响应状态码:200(成功响应)、500(失败响应),",allowableValues ="200,500" )
    private int code;

    @ApiModelProperty("描述信息")
    private String msg;

    @ApiModelProperty("数据")
    private T data;

    public static <T> Result<T> success(int code,String msg,T data){
        return new Result<T>(code,msg,data);
    }

    public static <T> Result<T> success(int code,String msg){
        return new Result<T>(code,msg,null);
    }

    public static <T> Result<T> success(String msg,T data){
        return new Result<T>(SUCCESSFUL_CODE,msg,data);
    }
    public static <T> Result<T> success(T data){
        return Result.success(COMMON_SUCCESSFUL_MSG,data);
    }

    public static <T> Result<T> success(String msg){
        return Result.success(msg,null);
    }

    public static <T> Result<T> success(){
        return Result.success(COMMON_SUCCESSFUL_MSG,null);
    }


    public static <T> Result<T> error(int code,String msg){
        return new Result<T>(code,msg,null);
    }

    public static <T> Result<T> error(String msg){
        return new Result<T>(SERVER_ERROR_CODE,msg,null);
    }

    public static <T> Result<T> error(){
        return new Result<T>(SERVER_ERROR_CODE, COMMON_ERROR_MSG,null);
    }



}
